package com.neulogistics.core.substation.domain.model.enumeration;

import com.neulogistics.core.substation.domain.exception.SubstationDomainException;
import com.neulogistics.infrastructure.common.serviceresult.ErrorCode;
import com.neulogistics.infrastructure.ddd.domain.seedwork.Enumeration;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class TaskStatus extends Enumeration {

    public static final int To_Be_Shipped_Id = 0;
    public static final int To_Be_Assigned_Id = 1;
    public static final int To_Be_Picked_Id = 2;
    public static final int To_Be_Delivery_Id = 3;
    public static final int Completed_Id = 4;

    public static TaskStatus To_Be_Shipped = new TaskStatus(To_Be_Shipped_Id, "To_Be_Shipped");
    public static TaskStatus To_Be_Assigned = new TaskStatus(To_Be_Assigned_Id, "To_Be_Assigned");
    public static TaskStatus To_Be_Picked = new TaskStatus(To_Be_Picked_Id, "To_Be_Picked");
    public static TaskStatus To_Be_Delivery = new TaskStatus(To_Be_Delivery_Id, "To_Be_Delivery");
    public static TaskStatus Completed = new TaskStatus(Completed_Id, "Completed");


    protected TaskStatus(int id, String name) {
        super(id, name);
    }

    private static List<TaskStatus> list = Arrays.asList(
            To_Be_Shipped,
            To_Be_Assigned,
            To_Be_Delivery,
            To_Be_Picked,
            Completed);

    public static List<TaskStatus> getList(){return list;}

    public static TaskStatus fromName(String name) throws SubstationDomainException {
        Optional<TaskStatus> optional = list.stream().filter(p -> p.name.equals(name)).findFirst();

        if (optional.isPresent()){
            return optional.get();
        }
        else {
            throw new SubstationDomainException(
                    ErrorCode.OPERATION_ERROR,
                    String.format("Possible values for {%s}: %s",
                            TaskStatus.class.getSimpleName(),
                            list.stream()
                                    .map(p -> p.name)
                                    .collect(Collectors.joining(",")))
            );
        }
    }

    @Override
    public int compareTo(Object o) {
        return 0;
    }
}
